var selectedItem1 = null;
var selectedItem2 = null;
var indexSelected = null;
function setListCritics(){
	//document.getElementById("cmbPerson1").selectedIndex
	var cmb1 = document.getElementById("cmbPerson1");
	initCmb(cmb1);
	selectedItem1 = cmb1.options[cmb1.selectedIndex];
	var cmb2 = document.getElementById("cmbPerson2");
	initCmb(cmb2);
	var cmbRec = document.getElementById("cmbRecomendacion");
	initCmb(cmbRec);
	var cmbtopP = document.getElementById("cmbTopMatches");
	initCmb(cmbtopP);
	var cmbtopPelis = document.getElementById("cmbTopMatchesPelis");
	initCmbPelis(cmbtopPelis);
	
}

function initCmbPelis(target){

		target.options[0] = new Option("Selected...","","defauldSelected");
		target.options[1] = new Option("Lady in the Water","Lady in the Water");
		target.options[2] = new Option("Snakes on a Plane","Snakes on a Plane");
		target.options[3] = new Option("Just My Luck","Just My Luck");
		target.options[4] = new Option("Superman Returns","Superman Returns");
		target.options[5] = new Option("You, Me and Dupree","You, Me and Dupree");
		target.options[6] = new Option("The Night Listener","The Night Listener");
	
}

function initCmb(target){
/*
	target.options[0] = new Option("Selected...","","defauldSelected");
	target.options[1] = new Option("Lady in the Water","Lady in the Water");
	target.options[2] = new Option("Snakes on a Plane","Snakes on a Plane");
	target.options[3] = new Option("ust My Luck","ust My Luck");
	target.options[4] = new Option("Superman Returns","Superman Returns");
	target.options[5] = new Option("You, Me and Dupree","You, Me and Dupree");
	target.options[6] = new Option("The Night Listener","The Night Listener");
	target.options[7] = new Option("Lisa Rose","Lisa Rose");
*/
	target.options[0] = new Option("Selected...","","defauldSelected");
	target.options[1] = new Option("Lisa Rose","Lisa Rose");
	target.options[2] = new Option("Gene Seymour","Gene Seymour");
	target.options[3] = new Option("Michael Phillips","Michael Phillips");
	target.options[4] = new Option("Claudia Puig","Claudia Puig");
	target.options[5] = new Option("Mick LaSalle","Mick LaSalle");
	target.options[6] = new Option("Jack Matthews","Jack Matthews");
	target.options[7] = new Option("Toby","Toby");
}

function removeItem(target,index){
	var cmbTarget = document.getElementById(target);
	initCmb(cmbTarget);
	if( index != 0 ){
		cmbTarget.options[index] = null;
	}
}

function fnSendPopupView(idDetails){
	
		$("#details_popup_content").html("&nbsp;");
		var strUrl = 'detailsfile.do';
		/*alert("det: "+idDetails);*/
		$.ajax({
			type: "POST",
			url: strUrl,
			data: "idFile="+idDetails,
			success: function(msg){
				//alert("success"+msg);
				$("#details_popup_content").html(msg);
				fnShowDetails();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("error"+XMLHttpRequest+textStatus+errorThrown);
				/*$("#msgError").html("Seleecione un critico para TopMatches Peliculas");
				$("#msgError").fadeIn().animate({opacity: 1.0}, 3000);*/
			}
		});
}

function fnSendVote(sender){
	/*alert("ser: "+$("#frmRatings").serialize());*/
	fnGet("msgErrorR").style.display = "none";
	if(validateRadio()){
		var strUrl = 'ratingsvt.do';
		$.ajax({
			type: "POST",
			url: strUrl,
			data: $("#frmRatings").serialize(),
			success: function(msg){
				sender.disabled = true;
				/*alert("success"+msg);*/
				$("#msgErrorR").html("&nbsp;Gracias por su voto");
				$("#msgErrorR").fadeIn().animate({opacity: 1.0}, 3000);
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("error"+XMLHttpRequest+textStatus+errorThrown);
			}
		});
	}else{

		$("#msgErrorR").html("&nbsp;Debe seleccionar un numero de voto");
		$("#msgErrorR").fadeIn().animate({opacity: 1.0}, 3000);
	}
}

function fnSendTop5(idDetails){
	
	var datos = "top5=1&fileindex="+idDetails;
	/*alert("datos: "+datos);*/
	var strUrl = 'top5Svt.do';
	$.ajax({
		type: "POST",
		url: strUrl,
		data: datos,
		success: function(msg){
			//	alert("success"+msg);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("error"+XMLHttpRequest+textStatus+errorThrown);
		}
	});
}


function fnSendRecomendaciones(){
	
	/*var datos = "top5=1&fileindex="+idDetails;*/
	/*alert("datos: "+datos);*/
	var strUrl = 'recomendation.do';
	$.ajax({
		type: "POST",
		url: strUrl,
		success: function(msg){
				/*alert("success"+msg);*/
				$("#detailsRecomendation").html(msg);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("error"+XMLHttpRequest+textStatus+errorThrown);
		}
	});
}


function fnGet(target){
	return document.getElementById(target);
}

function validateRadio(){
	var ret = false;
	for ( var i = 1; i < 11; i++ ) {
		/*
		alert("i:"+i);
		alert("ch"+fnGet("voto"+i).checked);*/
	    
		if ( fnGet("voto"+i).checked ) {
	    	ret = true;
	    }
	}
	return ret;
}

function  modalOpen (dialog) {
	dialog.overlay.fadeIn('fast', function () {
		dialog.container.fadeIn('fast', function () {
			dialog.data.hide().slideDown('fast');
		});
	});
}

function  simplemodal_close (dialog) {
	dialog.data.fadeOut('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.slideUp('fast', function () {
				$.modal.close();
				sendTagsFive();
			});
		});
	});
}

function fnShowDetails(){
	$("#details_popup").modal({onOpen: modalOpen, onClose: simplemodal_close});
}